package com.hongdee.insurance.dict.service.impl;

import com.hongdee.common.util.StringUtil;
import com.hongdee.common.util.TokenUtil;
import com.hongdee.insurance.dict.dao.ITInsuranceDictDao;
import com.hongdee.insurance.dict.service.ITInsuranceDictService;
import com.hongdee.rbac.dept.entity.TBcOrgan;
import com.hongdee.rbac.dept.service.ITBcOrganService;
import jdk.nashorn.internal.objects.NativeObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TInsuranceDictServiceImpl implements ITInsuranceDictService {

    @Autowired
    private ITInsuranceDictDao dictDao;
    @Autowired
    private ITBcOrganService bcOrganService;

    @Override
    public List<Map> comboByArea(String uid) throws Exception {
        String companyId= TokenUtil.getCompanyId(uid);
        StringBuffer sql = new StringBuffer(" select * from T_BC_NEWDICT where  status='1' and   p_code = 'area'  ");
        List<String> params= new ArrayList<>();
        //判断是否直属集团
        if(!companyId.equals("0")){
            Map map=bcOrganService.info(companyId);
            sql.append(" and `code`=?  ");
            params.add(StringUtil.formatEmpty(map.get("oArea")));
        }
        List<Map<String, Object>> mapList = this.dictDao.list(sql.toString(),params.toArray());
        List<Map> resList = new ArrayList<Map>();
        Map temp;
        for (Map map : mapList) {
            temp = new HashMap();
            temp.put("label", map.get("label"));
            temp.put("value", map.get("code"));
            temp.put("id",map.get("id"));
            resList.add(temp);
        }
        return resList;
    }

}
